﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
using VisualWip.PresentationModel.WorkItem;

namespace VisualWip.PresentationModel
{
    public class WorkItemSizeTemplateSelector : DataTemplateSelector
    {
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            var workItem = item as WorkItemViewModel;
            if (workItem != null)
            {
                var template =
                    Application.Current.TryFindResource(String.Format(CultureInfo.InvariantCulture, "{0}WorkItemView",
                                                                      workItem.Size)) as DataTemplate;
                if (template != null)
                {
                    return template;
                }
            }

            return base.SelectTemplate(item, container);
        }
    }
}